<!DOCTYPE html>
<html>
<head>
    <title>Parallel Plate Capacitor Diagram</title>
</head>
<body>
<canvas id="physicsCanvas" width="600" height="450" style="border:1px solid #000;"></canvas>
<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');
    
    // --- Style and Configuration ---
    ctx.strokeStyle = '#333';
    ctx.fillStyle = '#333';
    ctx.lineWidth = 2;
    ctx.font = "20px Arial";
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';

    // --- Helper Function to draw double-headed arrow ---
    function drawDoubleArrow(ctx, x1, y1, x2, y2) {
        const headlen = 8;
        const dx = x2 - x1;
        const dy = y2 - y1;
        const angle = Math.atan2(dy, dx);
        
        ctx.beginPath();
        ctx.moveTo(x1, y1);
        ctx.lineTo(x2, y2);
        
        // Arrowhead at the end (x2, y2)
        ctx.moveTo(x2, y2);
        ctx.lineTo(x2 - headlen * Math.cos(angle - Math.PI / 6), y2 - headlen * Math.sin(angle - Math.PI / 6));
        ctx.moveTo(x2, y2);
        ctx.lineTo(x2 - headlen * Math.cos(angle + Math.PI / 6), y2 - headlen * Math.sin(angle + Math.PI / 6));

        // Arrowhead at the start (x1, y1)
        ctx.moveTo(x1, y1);
        ctx.lineTo(x1 + headlen * Math.cos(angle - Math.PI / 6), y1 + headlen * Math.sin(angle - Math.PI / 6));
        ctx.moveTo(x1, y1);
        ctx.lineTo(x1 + headlen * Math.cos(angle + Math.PI / 6), y1 + headlen * Math.sin(angle + Math.PI / 6));
        
        ctx.stroke();
    }

    // --- Drawing Parameters ---
    const plateWidth = 18;
    const plateHeight = 220;
    const d1 = 80;
    const d2 = 160; // As per problem context d2 = 2 * d1
    const yTop = 80;

    // Calculate x positions to center the diagram
    const totalContentWidth = 3 * plateWidth + d1 + d2;
    const xStart = (canvas.width - totalContentWidth) / 2;
    
    const xPlate1 = xStart;
    const xPlate2 = xStart + plateWidth + d1;
    const xPlate3 = xPlate2 + plateWidth + d2;

    // --- 1. Draw the Plates ---
    ctx.strokeRect(xPlate1, yTop, plateWidth, plateHeight);
    ctx.strokeRect(xPlate2, yTop, plateWidth, plateHeight);
    ctx.strokeRect(xPlate3, yTop, plateWidth, plateHeight);

    // --- 2. Draw the Connecting Wire ---
    // The wire connects the two outer plates, indicating they are at the same electrical potential.
    const wireYBottom = yTop + plateHeight + 50;
    
    // Create a single path for the wire for a cleaner look
    ctx.beginPath();
    ctx.moveTo(xPlate1 + plateWidth, yTop + plateHeight * 0.75); // Start on the inner face of the left plate
    ctx.lineTo(xPlate1 - 30, yTop + plateHeight * 0.75); // Go left
    ctx.lineTo(xPlate1 - 30, wireYBottom); // Go down
    ctx.lineTo(xPlate3 + 30, wireYBottom); // Go right
    ctx.lineTo(xPlate3 + 30, yTop + plateHeight * 0.75); // Go up
    ctx.lineTo(xPlate3, yTop + plateHeight * 0.75); // Connect to the inner face of the right plate
    // The image connects from the outer faces
    ctx.beginPath();
    ctx.moveTo(xPlate1, yTop + plateHeight * 0.75);
    ctx.lineTo(xPlate1 - 30, yTop + plateHeight * 0.75);
    ctx.lineTo(xPlate1 - 30, wireYBottom);
    ctx.lineTo(xPlate3 + plateWidth + 30, wireYBottom);
    ctx.lineTo(xPlate3 + plateWidth + 30, yTop + plateHeight * 0.75);
    ctx.lineTo(xPlate3 + plateWidth, yTop + plateHeight * 0.75);
    ctx.stroke();


    // --- 3. Draw Distance Markers ---
    const yArrow = yTop + plateHeight / 2;
    
    // d1 marker
    const x1_d1 = xPlate1 + plateWidth;
    const x2_d1 = xPlate2;
    drawDoubleArrow(ctx, x1_d1, yArrow, x2_d1, yArrow);
    
    const x_d1_text = (x1_d1 + x2_d1) / 2;
    const y_d_text = yArrow - 15;
    ctx.font = "italic 20px Arial";
    ctx.fillText("d", x_d1_text, y_d_text);
    ctx.font = "14px Arial";
    ctx.fillText("1", x_d1_text + 10, y_d_text + 4);

    // d2 marker
    const x1_d2 = xPlate2 + plateWidth;
    const x2_d2 = xPlate3;
    drawDoubleArrow(ctx, x1_d2, yArrow, x2_d2, yArrow);

    const x_d2_text = (x1_d2 + x2_d2) / 2;
    ctx.font = "italic 20px Arial";
    ctx.fillText("d", x_d2_text, y_d_text);
    ctx.font = "14px Arial";
    ctx.fillText("2", x_d2_text + 10, y_d_text + 4);
    
    // --- 4. Draw Charge Density Labels (σ1, σ2) ---
    const yLabel = yTop - 20;
    ctx.font = "24px Arial";
    
    // σ1 label
    const xSigma1 = xPlate2 - 15;
    ctx.fillText("σ", xSigma1, yLabel);
    ctx.font = "16px Arial";
    ctx.fillText("1", xSigma1 + 10, yLabel + 7);

    // σ2 label
    const xSigma2 = xPlate2 + plateWidth + 15;
    ctx.font = "24px Arial";
    ctx.fillText("σ", xSigma2, yLabel);
    ctx.font = "16px Arial";
    ctx.fillText("2", xSigma2 + 10, yLabel + 7);

    // --- 5. Draw Caption ---
    ctx.font = "24px 'KaiTi', 'SimSun', serif";
    const yCaption = canvas.height - 30;
    ctx.fillText("题 7 图", canvas.width / 2, yCaption);

</script>
</body>
</html>